/*
 *  Cero Project - Copyright   2006 The Cero Developement Team 
 *  (Michael Laguerre, Camille Roux, Matthieu Segret, Mathieu Sivade) 
 * 
 *  This program is free software; you can redistribute it and/or modify it 
 *  under the terms of the GNU General Public License as published by the Free 
 *  Software Foundation; either version 2 of the License, or (at your option) 
 *  any later version.
 * 
 *  This program is distributed in the hope that it will be useful, but 
 *  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
 *  or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 
 *  for more details.
 */

package org.ceroproject.games.base;

import java.util.ArrayList;
import java.util.Collection;

import org.ceroproject.games.Card;
import org.ceroproject.games.Zone;


public class ZoneFile extends AbstractZone {

	public ZoneFile(String name, Collection<Card> cards) {
		super(name, cards);
	}

	public ZoneFile(String name) {
		super(name);
	}

	protected void addCard(Zone from, Card card) {
		cards.add(0, card);
		cards.resort();
		feedCardIn(from, card);
	}

	public Card getTopCard() {
		if (cards.size() > 0)
			return cards.getSortedList().get(cards.getSortedList().size() - 1);
		return null;
	}
	
	public Collection<Card> drawCards(Zone to, int quantity) {
		if (quantity > this.getSortedList().size())
			quantity = this.getSortedList().size();
		Collection<Card> result = new ArrayList<Card>(cards.subList(0, quantity));
		this.moveCards(result, to);
		return result;
	}

}
